﻿<?php
require_once("function.php");
judgeLogin();
//error_reporting(0);

			//统计数据获取-添加剂
			//上限值 体重*adi
			$user_mail = $_SESSION['login_mail'];
			
			$username = getUserNick($user_mail);
			
			$weight = getUserWeight($username);
			
			$foodNameLimit = getUserEatFoodName($username);
			//print_r($foodNameLimit);
			
			$LimitData = array();
	
			foreach($foodNameLimit as $key=>$foodName)
			{
				$limitData[] = getLimitValue($weight,$foodName);
			}
			
			foreach($limitData as $keyLimit=>$valueLimit)
			{
				foreach($valueLimit as $keyLimit1=>$valueLimit1)
				{
					$limit[$keyLimit1] = $valueLimit1;
				}
			}
			//print_r($limit);
			
			
			//unset($LimitData);
			//print_r($limit);
			//echo "<br />";


			//实际值 净含量*最大使用量
			
			//返回净含量和食品名称
			$actualNetcontent = getActualNetcontent($username);
			//print_r($actualNetcontent); 
			
			//返回食品名称和添加剂值
			$actualData = array();
			
			foreach($actualNetcontent as $foodNameValue=>$netcontent)
			{
				$actualData[] = getActualValue($foodNameValue,$netcontent);
			}
			
			//print_r($actualData); 
			//echo "<hr />";
			
			//键名相同的值相加 rebuild a array
			$actualHandle = rebuild_array($actualData);
			
			//删除值为空的数组元素
			foreach($actualHandle as $k=>$v)
			{
				if($v == '')
				{
					unset($actualHandle[$k]);
				}else
				{
					$actual[$k] = $v;
				}
			}
			
			//unset($actualData);
			//print_r($actual); 
			//echo "<br />";

			//处理添加剂超标量
			$countData = array();
		
			foreach($limit as $key=>$value)
			{
				foreach($actual as $k=>$v)
				{	//比较同一种添加剂的上限值和实际值
					if($key == $k)
					{	//实际值>上限值，求出超出额
						if($v > $value)
						{//echo $key,$value;echo $k,$v;
							$countData[$key] = $v - $value;	

						}//end if $v > $value
						else
						{
							$countData[$key] = 0;	
						}
					}//end if $key = $k
				}//end foreach $actual
			}//end foreach $limit
				//Print_r($countData);
		//unset($actual);
		foreach($actual as $kk=>$vv)
		{
			foreach($countData as $kk1=>$vv1)
			{
				if($kk == $kk1)
				{
					$handleChaoBiao[$kk] = $vv1;
				}
			}
		}
		//Print_r($handleChaoBiao);
		//echo "<br />";
			
			//用户得分
			$userId = getUserId($_SESSION['login_mail']);
			$userHistoryScore = getUserHistoryScore($userId);
			
			//print_r($userHistoryScore);
			
			//echo $userHistoryScore[0];

			//各类食物的比重
			$categoryRateHandle = getEatedFoodCategoryRate($userId);

			//键名相同的值相加 rebuild a array
			$categoryRateEmpty = rebuild_arra($categoryRateHandle);
			//print_r($categoryRateEmpty);echo "<hr>";
			
			//删除值为空的数组元素
			$categoryRate = delArrayRepeat($categoryRateEmpty);
			//print_r($categoryRate);
			//总重量$sum
			(float)$sum = 0.0;
			foreach($categoryRate as $key=>$value)
			{
				$sum = $sum + $value;
			}
			//echo $sum;
			
			//计算各种食品种类所占的比重
			foreach($categoryRate as $key1=>$value1)
			{
				$value2 = $value1 / $sum;
				
				$value3 = round($value2, 3);
				
				$value4 = $value3 * 100;
				
				$rate[] = array($key1,$value4);
			}
			
			function showBiao($array){
	for($i=0;$i<1000;$i++){
		if($array[$i][0]=='')break;
		if($i==0){
			$name=$array[0][0];
			$value=$array[0][1];
		}else{
			$name.="|".$array[$i][0];
			$value.="|".$array[$i][1];
		}
		
	}
	$temp[0]=$name;
	$temp[1]=$value;
	return $temp;
}

			//获取用户吃了的食物的表
			$lei_sql_food_user_data=mysql_query("select * from `food_user_data` where `user_id` = '$userId' ");
			$lei_row_food_user_data = mysql_fetch_array($lei_sql_food_user_data);
			
			//获取用户的得分情况表
			$lei_sql=mysql_query("select * from `food_user_score` where `user_id` = '$userId' ");
			$lei_row = mysql_fetch_array($lei_sql);
			
			$biao1=showBiao($rate);

				?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="食品笔记,食品,食品安全,饮食,饮食安全,生活"><!--SEO关键字-->
<meta name="description" content="食品笔记，你的饮食安全卫士"><!--SEO描述-->
<link rel="shortcut icon" type="image/ico" href="images/favicon.ico"><!--选项卡图标-->
<title>食品笔记 - 让生活更健康</title>
<link rel="shortcut icon" type="image/ico" href="images/favicon.ico"><!--选项卡图标-->
<link rel="stylesheet" href="css/base.css">
<link rel="stylesheet" href="css/common.css">
<link rel="stylesheet" href="css/style.css">
<!--[if ie]>
<link rel="stylesheet" href="css/ie.css">
<script type="text/javascript" src="js/DD_belatedPNG.js" ></script>
<script type="text/javascript">
DD_belatedPNG.fix('.png');/*在需要png透明的元素里面加上.png样式即可（class="png"）*/
</script>
<![endif]-->
</head>

<body>
	<div class="header w pr"><!-- header -->
		<div class="index-header w960 bc">
			<a href="home.php" class="score_logo score_img dib png fl mt10"></a>
			<div class="header_right fr">
				<ul class="header_nav fl tc fb f12 h mt5">
					<li><a href="home.php">首 页</a></li>
					<li><a href="timeline_new.php" class="header_nav_hover">时光轴</a></li>
					<li><a href="newsmap.php">食品新闻</a></li>
					<li><a href="food.php">选食专栏</a></li>					
					<li><a href="share.php">分享</a></li>
				</ul>
				<a href="massage.php" class="header_myMessage tc fr ml5" title="私信"></a><!-- 私信 -->
				
				<div class="header_myInfo fr f14 h pr">
					<a href="#" class="header_setup"><img src="<?php if(!empty($_SESSION['qq_nickname'])): echo $_SESSION['qq_photoUrl']; else: echo showUserPhoto();endif;?>" alt="" class="fl" /></a><!-- user_avatar -->
					<a href="#" class="fl header_setup"><?php echo showUserName();?></a><!-- user_nickname -->
					<div class="header_myInfoArrow score_img fl"></div>
					<ul class="header_hideInfo none pa tc w"><!-- hide_info -->
						<li><a href="#" class="header_setup">个人设置</a></li>
						<li><a href="modifymail.php">修改邮箱</a></li>
						<li><a href="password.php">修改密码</a></li>
						<li><a href="login_out.php">退出登录</a></li>
					</ul>
				</div>
			</div>
		</div>
	</div><!-- end_header -->
	<div class="score_main oh h pr">
		<div class="main w960 bc h oh">
			<div class="user_message">
				<div class="user_header">
					<img src="images/female_m.png" alt class="header_pic">
				</div>
				<div class="user_message_inner">
					<p>
						<a href="#" class="user_name"><?php echo showUserName();?></a>						
					</p>
					<ul class="user_other_message">
						<li>
							<img src="images/user_header.png" class="png">
							<a href="#">男</a>
						</li>
						<li class="user_address">
							<img src="images/user_address.png" class="png">
							<a href="#">长沙</a>
						</li>
						<li class="user_age">
							<img src="images/user_age.png" class="png">
							<a href="#">19</a>
						</li>
					</ul>
				</div>
			</div>
			<div class="user_timeline fl pr pb50">
				<div class="adorn_line">
					<div></div>
					<div></div>
					<div></div>
				</div>
				<div class="side_line pa">
					<ul class="side_line_inner"><!-- 时间轴导航 -->
						<li><a href="#" class="timeline_current" id="time_now">现在</a></li>
						<li><a href="#" id="time_2012_10">10月</a></li>
						<li><a href="#" id="time_2012_8">8月</a></li>
						<li><a href="#" id="time_2012_4">4月</a></li>
						<li><a href="#" id="time_2012">2012</a></li>
						<li><a href="#" id="time_2011_12">12月</a></li>
						<li><a href="#" id="time_2011">2011</a></li>
						<li><a href="#" id="time_register">注册日</a></li>
					</ul>
				</div>
				<div class="timeline_wrap fl">

					<div class="timeline_container pr time_now time_2012_10"><!-- timeline_container -->
						<div class="sanjiao pa png"></div><!-- 三角形 -->
						<div class="timeline_dot pa png"></div><!-- 时光点 -->
						<div class="eat_time oh mb10">
							<div class="eat_date">
								<a href="#">2012-10-3:</a>
							</div>
							<div class="eat_score">
								<a href="#"><?php echo $lei_row[user_score];?></a>
							</div>
							<div class="food_kinds">
								<div class="food_kinds_inner">
									<span>食品:</span>
								</div>
								<div class="foods_name">
									<p>
									<a href="#"><?php echo $lei_row_food_user_data['eatwhat'];?></a>
									<span><a href="#"><?php echo $lei_row_food_user_data['eathowmany'];?>kg</a></span></p>
									<p><a href="#">上好佳田园薯片</a>
									<span><a href="#">0.15kg</a></span></p>
								</div>
							</div>
						</div>
						<div class="table_contain oh pb40">
							<div class="food_kind_table">
								<p>食品类型</p>
								<?php if($biao1[0]!=""){?>
					<div id="report_foodTypePie" class="bc mb50 mt20"></div>
					<?php }else{
						//没有用户数据时输出
						echo "<div id='report_foodTypePie' class='bc mb50 mt20' style='display:none'></div>";
						echo "<div class=\"report_noData mt50 tc f20\">Sorry ˇ_ˇ ！你今天还没有饮食记录！</div>";
						}?>
							</div>
						
						</div>
						<div class="my_note">
							<span>我的笔记：</span><a href="#">今天吃的很健康，明天也要加油</a><br>
							<input type="button"  class="good_pic">
							<input type="button"  class="comment_pic">
						</div>
						<div class="b1_1"><?php echo $biao1[0];?></div>
						<div class="b1_2"><?php echo $biao1[1];?></div>
					</div>
				
					
				
					
					
					
					
					
					
					
					
					
					
					
					<div class="timeline_container pr time_2012_8">
						<div class="sanjiao pa"></div><!-- 三角形 -->
						<div class="timeline_dot pa"></div><!-- 时光点 -->
						<div class="eat_time oh mb10">
							<div class="eat_date">
								<a href="#">2012-8-3:</a>
							</div>
							<div class="eat_score">
								<a href="#">94'</a>
							</div>
							<div class="food_kinds">
								<div class="food_kinds_inner">
									<span>食品:</span>
								</div>
								<div class="foods_name">
									<p>
									<a href="#">康师傅红烧牛肉面</a>
									<span><a href="#">0.15kg</a></span></p>
									<p><a href="#">上好佳田园薯片</a>
									<span><a href="#">0.15kg</a></span></p>
								</div>
							</div>
						</div>
						<div class="table_contain oh pb40">
							<div class="food_kind_table">
								<p>食品类型</p>
								<div class="footkind_table_inner">
									<a href="images/foodkind_up.png"><img src="images/foodkind_up.png" id="bd" class="png" /></a>
								</div>
							</div>
							<div class="food_report">
								<p>添加剂报告</p>
								<div class="footreport_inner">
									<a href="images/report_up.png"><img src="images/report.png" class="png" /></a>
								</div>
							</div>
						</div>
						<div class="my_note">
							<span>我的笔记：</span><a href="#">今天吃的很健康，明天也要加油</a><br>
							<input type="button"  class="good_pic">
							<input type="button"  class="comment_pic">
						</div>
					</div>

					<div class="timeline_container pr time_2012_4 time_2012">
						<div class="sanjiao pa"></div><!-- 三角形 -->
						<div class="timeline_dot pa"></div><!-- 时光点 -->
						<div class="eat_time oh mb10">
							<div class="eat_date">
								<a href="#">2012-4-3:</a>
							</div>
							<div class="eat_score">
								<a href="#">94'</a>
							</div>
							<div class="food_kinds">
								<div class="food_kinds_inner">
									<span>食品:</span>
								</div>
								<div class="foods_name">
									<p>
									<a href="#">康师傅红烧牛肉面</a>
									<span><a href="#">0.15kg</a></span></p>
									<p><a href="#">上好佳田园薯片</a>
									<span><a href="#">0.15kg</a></span></p>
								</div>
							</div>
						</div>
						<div class="table_contain oh pb40">
							<div class="food_kind_table">
								<p>食品类型</p>
								<div class="footkind_table_inner">
									<a href="images/foodkind_up.png"><img src="images/foodkind_up.png" id="bd" class="png" /></a>
								</div>
							</div>
							<div class="food_report">
								<p>添加剂报告</p>
								<div class="footreport_inner">
									<a href="images/report_up.png"><img src="images/report.png" class="png" /></a>
								</div>
							</div>
						</div>
						<div class="my_note">
							<span>我的笔记：</span><a href="#">今天吃的很健康，明天也要加油</a><br>
							<input type="button"  class="good_pic">
							<input type="button"  class="comment_pic">
						</div>
					</div>

					<div class="timeline_container pr time_2011_12 time_2011">
						<div class="sanjiao pa"></div><!-- 三角形 -->
						<div class="timeline_dot pa"></div><!-- 时光点 -->
						<div class="eat_time oh mb10">
							<div class="eat_date">
								<a href="#">2011-12-3:</a>
							</div>
							<div class="eat_score">
								<a href="#">94'</a>
							</div>
							<div class="food_kinds">
								<div class="food_kinds_inner">
									<span>食品:</span>
								</div>
								<div class="foods_name">
									<p>
									<a href="#">康师傅红烧牛肉面</a>
									<span><a href="#">0.15kg</a></span></p>
									<p><a href="#">上好佳田园薯片</a>
									<span><a href="#">0.15kg</a></span></p>
								</div>
							</div>
						</div>
						<div class="table_contain oh pb40">
							<div class="food_kind_table">
								<p>食品类型</p>
								<div class="footkind_table_inner">
									<a href="images/foodkind_up.png"><img src="images/foodkind_up.png" id="bd" class="png" /></a>
								</div>
							</div>
							<div class="food_report">
								<p>添加剂报告</p>
								<div class="footreport_inner">
									<a href="images/report_up.png"><img src="images/report.png" class="png" /></a>
								</div>
							</div>
						</div>
						<div class="my_note">
							<span>我的笔记：</span><a href="#">今天吃的很健康，明天也要加油</a><br>
							<input type="button"  class="good_pic">
							<input type="button"  class="comment_pic">
						</div>
					</div>

					<div class="timeline_container pr time_register">
						<div class="sanjiao pa"></div><!-- 三角形 -->
						<div class="timeline_dot pa"></div><!-- 时光点 -->
						<div class="day_record_board oh mb10 ml30">
							注册于2011年3月4日
						</div>
					</div>

				</div>

				<div class="adorn_line oh">
					<div></div>
					<div></div>
					<div></div>
				</div>

			</div>
		</div>
	</div>
	
	<!--<div class="right_bar">
		
	</div>-->
	<div class="footer w"><!-- footer -->
		<div class="w960 bc pr tc">
			<p class="pt30"><a href="#" class="iphone-app f12 a3 mr10 dib oh"><span class="iphone-app-img dib png fl ml5"></span>iphone应用</a>
			<a href="foodnote.apk" class="android-app f12 a3 dib oh"><span class="android-app-img dib png fl ml5"></span>android应用</a></p>
			<p class="f12 tc mt10"><a href="#" class="a3">关于我们</a><span class="ml10 mr10">|</span><a href="#" class="a3">使用条款</a><span class="ml10 mr10">|</span><a href="#" class="a3">常见问题</a></p>
			<p class="a3 f12 c91 mt10">Copyright &copy; 2011-2012 Foodnote&nbsp;&nbsp;&nbsp;&nbsp; 湘ICP备09004495号-5</p>
		</div>
	</div><!-- end_footer -->
	
<script type="text/javascript" src="js/jquery-1.6.min.js"></script>
<script type="text/javascript" src="js/highcharts.js"></script>
<script type="text/javascript" src="js/exporting.js"></script>
<script type="text/javascript" src="js/script.js"></script>
<script type="text/javascript" src="js/ajax.js"></script>
</body>
</html>